<template>
	<view>
		<view class="wai">
			<view class="title">{{list.post_title}}</view>
			<view class="acea-row shoruc row-between-wrapper">
				<view class="laitiem acea-row"><text class="laiyuan textline">来源：{{list.post_source}}</text> <text>发布时间：{{list.published_time}}</text></view>
				<view class="hsou acea-row" v-if="!shouchang" @click="shou">
					<image src="../../static/xx.png"></image>
					<view class="">收藏</view>
				</view>
				<view class="hsou  hsou2 acea-row" @click="qx" v-else>
					<image src="../../static/xx2.png"></image>
					<view class="">已收藏</view>
				</view>
			</view>
			<view class="infos" v-html="list.post_content">
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				shouchang: true,
				cid: '',
				id: ''
			}
		},
		onLoad(res) {
			this.cid = res.cid
			this.id = res.id
			this.liste()
		},
		methods: {
			liste(res) {

				var id = uni.getStorageSync('ids')
				var that = this,
					datas = {
						cid: that.cid,
						id: that.id,
						user_id: id
					}
				that.$api('/portal/index/details', {
					datas: datas
				}, function(res) {
					console.log(res)

					that.list = res.data.data
					if (res.data.data.issc == true) {
						that.shouchang = true
					} else {
						that.shouchang = false
					}
					var jweixin = require('jweixin-module')

					console.log(jweixin)
						var urls = window.location.href
					that.$api('/portal/index/jsconfig', {datas:{url:urls}}, function(res) {
						console.log(res)
						var s = res.data.data
						jweixin.config({
						    debug: false,
						    appId: s.appId,
						    timestamp: s.timestamp,
						    nonceStr: s.nonceStr,
						    signature:s.signature,
						    jsApiList: ["updateTimelineShareData","updateAppMessageShareData"]
						});
						jweixin.ready(function(){
							jweixin.updateTimelineShareData({
									title: that.list.post_title, // 分享标题
								    link: urls, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
								    imgUrl: 'http://api.haimiantv.cn/upload/default/20200426/86ea4921376b6656f24fbb40e674b361.png', // 分享图标
								    success: function () {
								      // 设置成功
									  console.log(1)

								    }
							})
							jweixin.updateAppMessageShareData({
								title:that.list.post_title, // 分享标题
								desc: that.list.post_keywords, // 分享描述
								link: urls, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
								imgUrl: 'http://api.haimiantv.cn/upload/default/20200426/86ea4921376b6656f24fbb40e674b361.png', // 分享图标
								success: function () {
								  // 设置成功
								}
							  })



						})
						jweixin.error(function(res){
							console.log(res)
						})
					})



				})
			},
			shou() {
				var that = this
				var id = uni.getStorageSync('ids')
				console.log(id)
				this.$api('/portal/index/sc', {
					datas: {
						id: that.list.id,
						user_id: id
					}
				}, function(res) {
					console.log(res)
					if (res.data.code == 200) {
						uni.showToast({
							title: res.data.msg,
							icon: 'success',
							duration: 1500
						})
						setTimeout(function(){
							that.liste()
						},1000)


					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
							duration: 1500
						})
					}


				})
			},
			qx() {
				var that = this
				var id = uni.getStorageSync('ids')
				console.log(id)
				this.$api('/portal/index/qxsc', {
					datas: {
						id: that.list.id,
						user_id: id
					}
				}, function(res) {
					console.log(res)
					if (res.data.code == 200) {
						uni.showToast({
							title: res.data.msg,
							icon: 'success',
							duration: 1500
						})
						setTimeout(function(){
							that.liste()
						},1000)
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
							duration: 1500
						})
					}


				})
			}
		}
	}
</script>

<style>
	@import url("./kepuxq.css");

	.infos>>>img {
		max-width: 100% !important;
	}
</style>
